package com.zlfund.cat.zjgsmk.ui.channel;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.zlfund.cat.zjgsmk.R;
import com.zlfund.cat.zjgsmk.adapter.AdapterFactory;
import com.zlfund.cat.zjgsmk.adapter.RecyclerViewAdapter;
import com.zlfund.cat.zjgsmk.adapter.RecyclerViewHolder;
import com.zlfund.cat.zjgsmk.adapter.RecyclerViewOneTypeAdapterHelper;
import com.zlfund.cat.zjgsmk.ui.base.BaseActivity;
import com.zlfund.cat.zjgsmk.util.BitmapHelper;
import com.zlfund.cat.zjgsmk.util.filepick.LocalImageDirectory;
import com.zlfund.cat.zjgsmk.widget.ThumbnailsView;

import java.util.ArrayList;

import butterknife.BindView;

public class AlbumActivity extends BaseActivity {

    @BindView(R.id.rv)
    RecyclerView mRv;
    private RecyclerViewAdapter<LocalImageDirectory> mAdapter;
    private ArrayList<LocalImageDirectory> mDirectories;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    protected void setContentView() {
        setContentView(R.layout.activity_album);
    }

    @Override
    protected void setListener() {

    }

    @Override
    protected void initData() {
        mAdapter = AdapterFactory.singleTon().createOneTypeRvAdapter(mContext, new RecyclerViewOneTypeAdapterHelper<LocalImageDirectory>(R.layout.item_album) {
            @Override
            public void initViews(RecyclerViewHolder holder, int position, LocalImageDirectory bean) {
                ThumbnailsView iv = holder.getView(R.id.iv_thumb, ThumbnailsView.class);
                Bitmap bm = BitmapHelper.compress(bean.getImageNum().get(0), iv.getWidth(), iv.getHeight());
                iv.setBitmaps(bm);
                holder.getView(R.id.tv_name, TextView.class).setText(bean.getFileName());
                holder.getView(R.id.tv_num, TextView.class).setText(String.valueOf(bean.getImageNum().size()));
            }
        });
        mRv.setLayoutManager(new LinearLayoutManager(mContext));
        mRv.setAdapter(mAdapter);
        mDirectories = mIntent.getParcelableArrayListExtra("album");
        mAdapter.setList(mDirectories);
    }
}
